//
//  BXGCommentReplyViewModel.m
//  CommunityPrj
//
//  Created by apple on 2017/9/2.
//  Copyright © 2017年 itheima. All rights reserved.
//

#import "BXGCommentReplyViewModel.h"
#import "BXGCommentDataModel.h"
#import "BXGNineGridLayoutHelper.h"
#import "BXGUtil.h"

@implementation BXGCommentReplyViewModel
-(void)setDataModel:(BXGCommentDataModel *)dataModel
{
    _dataModel = dataModel;
    [self parseData:_dataModel];
}

-(void)parseData:(BXGCommentDataModel *)dataModel
{
    _txtFrame = CGRectZero;
    _contentMediaFrame = CGRectZero;
    _cellHeight = 0;
    _nineGridLayout= [BXGNineGridLayoutHelper new];

    int txtLabelHeight = 0;
    int mediaContentHeight = 0;
    
    if(dataModel.text)
    {
        txtLabelHeight = [[BXGUtil shareInstance] calculateFontWidthByString:dataModel.text
                                                                        font:[UIFont systemFontOfSize:10]
                                                               limitMaxWidth:kReplyTableViewWidth];
    }
    //_cellHeight += kReplyViewPadding;
    if(txtLabelHeight>0)
    {
        _txtFrame = CGRectMake(kReplyViewPadding, _cellHeight, kReplyTableViewWidth, txtLabelHeight);
        _cellHeight += txtLabelHeight;
        //_cellHeight += kReplyViewPaddingCell;
        NSLog(@"txtFrame(x=%lf, y=%lf, w=%lf, h=%lf)", _txtFrame.origin.x, _txtFrame.origin.y, _txtFrame.size.width, _txtFrame.size.height);
    }
    
    //*
    if(dataModel.arrMediaImage && dataModel.arrMediaImage.count>0)
    {
        [_nineGridLayout gridWithSepcialWidth:kReplyTableViewWidth
                                   numPerRow:3
                                    totalNum:dataModel.arrMediaImage.count
                                 viewPadding:kReplyViewPadding
                             viewPaddingCell:kReplyViewPaddingCell];
        mediaContentHeight = _nineGridLayout.gridContainerSize.height;
    }
    if(mediaContentHeight>0)
    {
        _contentMediaFrame = CGRectMake(kReplyViewPadding, _cellHeight, kReplyMediaViewWidth, mediaContentHeight);
        _cellHeight += mediaContentHeight;
     //   _cellHeight += kReplyViewPaddingCell;
    }
    //*/
    //_cellHeight += kReplyViewPadding;
}

//-(CGFloat)cellHeight
//{
//    if(!_dataModel)
//    {
//        _cellHeight = 0;
//        return _cellHeight;
//    }
//
//    if(_cellHeight==0)
//    {
//        [self parseData:_dataModel];
//    }
//    return _cellHeight;
//}

@end
